package com.ydzt.fanka.server.deamon;

import java.sql.Connection;
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.ydzt.fanka.server.domain.ParamDefine;
import com.ydzt.fanka.server.space.consumer.SocketConsumerPool;
import com.ydzt.fanka.server.utils.JdbcUtils;



public class DeamonServer extends Thread{
	static Logger logger = Logger.getLogger(DeamonServer.class.getName());
	
	
	private Connection conn;
	private HashMap<String , ParamDefine> paramDefine;
	
	//构造器
	public DeamonServer(HashMap<String , ParamDefine> paramDefine,Connection conn){
		this.conn = conn;
		this.paramDefine = paramDefine;
	}
	
	public void run(){
		
		while(true){
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if(this.conn != null){
				this.conn = JdbcUtils.getConnectionForOracle();
				SocketConsumerPool.getInstans(10).initProcessPool(paramDefine,conn);
			}
			else{
				logger.error("进行数据库重连   5秒后重新连接数据库...");
				this.conn = JdbcUtils.getConnectionForOracle();
				logger.info("数据库已重新连接");
				SocketConsumerPool.getInstans(10).initProcessPool(paramDefine,conn);
			}
		}
		
	}
}
